package com.corgi.kotlin.kotlin.controller

import com.corgi.kotlin.kotlin.domain.TestPeople
import com.corgi.kotlin.kotlin.service.TestPeopleService
import org.springframework.beans.factory.annotation.Autowired
import org.springframework.web.bind.annotation.*

/**
 * @title: TestPeopleController
 * @description:
 * @author: dengmiao
 * @create: 2019-10-15 11:51
 **/
@RestController
@RequestMapping(value = "people")
class TestPeopleController {

    @Autowired
    val testPeopleService: TestPeopleService? = null

    @GetMapping(value = "getByLastName")
    fun getByLastName(@RequestParam(value = "lastName") lastName: String): List<TestPeople>? {

        return testPeopleService?.findByLastName(lastName)
    }

    @PostMapping(value = "add")
    fun add(@RequestBody testPeople: TestPeople): TestPeople? {

        return testPeopleService?.create(testPeople)
    }

    @GetMapping(value = "query")
    fun query(): MutableIterable<TestPeople>? {
        val people = testPeopleService?.retrieve()
        println("query result $people")
        return people
    }
}